//
//  CSBClubListSweeping.swift
//  CurSodoboAer
//
//  Created by CurSodoboAer on 2024/11/5.
//

import UIKit
import JDStatusBarNotification

class CSBClubListSweeping: UIViewController {
    
    var clubsListCSB:Array<Dictionary<String,String>> = Array<Dictionary<String,String>>()
    
    private let csbMontTitleViw = UILabel.init()
    private let csbBackComButton = UIButton.init()
    private lazy var CSBColorfulDataview: UICollectionView = {
        let cofullayout = UICollectionViewFlowLayout()
        cofullayout.scrollDirection = .vertical
        cofullayout.itemSize = CGSize(width: UIScreen.main.bounds.width - 24.xQQ, height: 150)
        cofullayout.minimumLineSpacing = 20
        var colorfulDataview = UICollectionView.init(frame: .zero, collectionViewLayout: cofullayout)
    
        colorfulDataview.delegate = self
        colorfulDataview.contentInset = UIEdgeInsets.init(top: 0, left: 0, bottom:30, right: 0)
        colorfulDataview.backgroundColor = .clear
       
        colorfulDataview.dataSource = self
       
        colorfulDataview.showsVerticalScrollIndicator = false
        colorfulDataview.register(CSBClubListCell.self, forCellWithReuseIdentifier: "CSBClubListCellID")
       
        return colorfulDataview
    }()
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor(red: 0.64, green: 0.41, blue: 0.98, alpha: 1)
        
        csbMontTitleViw.text = "Curling Clubs"
        csbMontTitleViw.textColor = .white
        csbMontTitleViw.font = UIFont(name: "Futura Medium", size: 24)
        
        csbBackComButton.setImage(UIImage.init(named: "csb_back"), for: .normal)
        csbBackComButton.addTarget(self, action: #selector(csbButtonClick), for: .touchUpInside)
        
        clubsListCSB = CSBFetcherAll.Hammer.loading_actionve_CSBData(pathCSB: "CSBClubInfo")
        
        addAotherCSB()
    }
    
    @objc func csbButtonClick()  {
        self.navigationController?.popViewController(animated: true)
    }
    private func addAotherCSB()  {
        view.addSubview(csbBackComButton)
        view.addSubview(csbMontTitleViw)
        
        let stattusBarHeight = UIApplication.shared.statusBarFrame.height
        csbBackComButton.snp.makeConstraints { make in
            make.leading.equalToSuperview().inset(12.xQQ)
            make.width.equalTo(24)
            make.height.equalTo(22)
            make.top.equalToSuperview().offset(stattusBarHeight + 15)
        }
        
        csbMontTitleViw.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            
            make.centerY.equalTo(csbBackComButton)
        }
        
        
        
        NotificationPresenter.shared.present("")
        NotificationPresenter.shared.displayActivityIndicator(true)
        
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1.0, execute: DispatchWorkItem(block: {
            NotificationPresenter.shared.dismiss()
            self.view.addSubview(self.CSBColorfulDataview)
            self.CSBColorfulDataview.snp.makeConstraints { make in
                make.leading.trailing.equalToSuperview().inset(12.xQQ)
                make.top.equalTo(self.csbMontTitleViw.snp.bottom).offset(27.xQQ)
                make.bottom.equalToSuperview()
            }
            
        }))
        
        
    }
}


extension CSBClubListSweeping:UICollectionViewDelegate,UICollectionViewDataSource{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        
        
        return clubsListCSB.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        
        
        let meizi = collectionView.dequeueReusableCell(withReuseIdentifier: "CSBClubListCellID", for: indexPath) as! CSBClubListCell
        meizi.backgroundColor = .clear
        meizi.comekwith(uhuie: clubsListCSB[indexPath.row])
        
        return meizi
        
    }
    
    
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        self.navigationController?.pushViewController(CSBClubXQSweeping.init(qugaoshCSB:[334,445],activeDataCSB: self.clubsListCSB[indexPath.row]), animated: true)
    }
    
}
